package work.mediway.mdm.core.thread;

import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;

import work.mediway.mdm.core.constant.MdmConstant;

/**
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2020/2/24
 */
public class DimplesTaskExecutor<T> {

    private ExecutorCompletionService<T> completionService;

    /**
     * 无参构造
     */
    public DimplesTaskExecutor() {
        this.completionService = new ExecutorCompletionService<>(DimplesThreadPoolExecutor.getExecutor(MdmConstant.SYSTEM_NAME));
    }

    /**
     * 有参构造
     *
     * @param threadPre 线程前缀
     */
    public DimplesTaskExecutor(String threadPre) {
        this.completionService = new ExecutorCompletionService<>(DimplesThreadPoolExecutor.getExecutor(threadPre));
    }

    /**
     * 获取有返回值的异步线程执行器
     *
     * @return 执行器
     */
    public ExecutorCompletionService<T> getCompletionService() {
        return completionService;
    }

    public static  <T> ExecutorCompletionService<T> getExecutorCompletionService() {
        DimplesTaskExecutor<T> dimplesTaskExecutor = new DimplesTaskExecutor<>();
        return dimplesTaskExecutor.completionService;
    }

    /**
     * 获取线程池
     *
     * @return 线程池
     */
    public ExecutorService getExecutorService() {
        return DimplesThreadPoolExecutor.getExecutor();
    }
}
